
# 编译并使用vad模块
# webrtc_vad 和 vad好像是独立的

cmake_minimum_required(VERSION 3.5)

project(vad-example)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_definitions("-DWEBRTC_LINUX -DWEBRTC_POSIX -DWEBRTC_NS_FLOAT")

# 必须要包含根目录
include_directories(     
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/webrtc
    ${PROJECT_SOURCE_DIR}/webrtc/base        
    ${PROJECT_SOURCE_DIR}/webrtc/system_wrapper/include    
    ${PROJECT_SOURCE_DIR}/webrtc/common_audio
    ${PROJECT_SOURCE_DIR}/webrtc/common_audio/signal_processing/include    
    ${PROJECT_SOURCE_DIR}/webrtc/common_audio/vad/include 
    ${PROJECT_SOURCE_DIR}/webrtc/common_audio/vad     
    ${PROJECT_SOURCE_DIR}/webrtc/common_audio/resampler/include
    # audio coding
    ${PROJECT_SOURCE_DIR}/webrtc/modules/audio_coding/codecs/isac/main/include
    ${PROJECT_SOURCE_DIR}/webrtc/modules/audio_coding/codecs/isac
    # audio processing
    ${PROJECT_SOURCE_DIR}/webrtc/modules/audio_processing/vad    
    # interface
    ${PROJECT_SOURCE_DIR}/webrtc/modules/interface
    # utility
    ${PROJECT_SOURCE_DIR}/webrtc/modules/utility/interface    
)

set(WEBRTC_SRC_   
    # 一些辅助函数    
    webrtc/base/checks.cc   
    webrtc/common_audio/fft4g.c 
    webrtc/common_audio/resampler/resampler.cc
    webrtc/common_types.cc    
    # 信号处理函数
    webrtc/common_audio/signal_processing/auto_correlation.c
    webrtc/common_audio/signal_processing/auto_corr_to_refl_coef.c
    webrtc/common_audio/signal_processing/complex_bit_reverse.c
    webrtc/common_audio/signal_processing/complex_fft.c
    webrtc/common_audio/signal_processing/copy_set_operations.c
    webrtc/common_audio/signal_processing/cross_correlation.c
    webrtc/common_audio/signal_processing/division_operations.c
    webrtc/common_audio/signal_processing/dot_product_with_scale.c
    webrtc/common_audio/signal_processing/downsample_fast.c
    webrtc/common_audio/signal_processing/energy.c
    webrtc/common_audio/signal_processing/filter_ar.c
    webrtc/common_audio/signal_processing/filter_ma_fast_q12.c
    webrtc/common_audio/signal_processing/get_hanning_window.c
    webrtc/common_audio/signal_processing/get_scaling_square.c
    webrtc/common_audio/signal_processing/ilbc_specific_functions.c
    webrtc/common_audio/signal_processing/levinson_durbin.c
    webrtc/common_audio/signal_processing/lpc_to_refl_coef.c
    webrtc/common_audio/signal_processing/min_max_operations.c
    webrtc/common_audio/signal_processing/randomization_functions.c
    webrtc/common_audio/signal_processing/refl_coef_to_lpc.c
    webrtc/common_audio/signal_processing/resample.c
    webrtc/common_audio/signal_processing/resample_48khz.c
    webrtc/common_audio/signal_processing/resample_by_2.c
    webrtc/common_audio/signal_processing/resample_by_2_internal.c
    webrtc/common_audio/signal_processing/resample_fractional.c
    webrtc/common_audio/signal_processing/splitting_filter.c
    webrtc/common_audio/signal_processing/sqrt_of_one_minus_x_squared.c
    webrtc/common_audio/signal_processing/vector_scaling_operations.c
    webrtc/common_audio/signal_processing/spl_init.c
    webrtc/common_audio/signal_processing/spl_sqrt.c
    # vad模块文件
    webrtc/common_audio/vad/vad.cc
    webrtc/common_audio/vad/vad_core.c
    webrtc/common_audio/vad/vad_filterbank.c
    webrtc/common_audio/vad/vad_gmm.c
    webrtc/common_audio/vad/vad_sp.c
    webrtc/common_audio/vad/webrtc_vad.c    
    # audio coding 模块
    webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.c
    webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_hist.c #
    webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_logist.c #
    webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.c
    webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.c
    webrtc/modules/audio_coding/codecs/isac/main/source/filter_functions.c #
    webrtc/modules/audio_coding/codecs/isac/main/source/filterbank_tables.c #
    webrtc/modules/audio_coding/codecs/isac/main/source/filterbanks.c #
    webrtc/modules/audio_coding/codecs/isac/main/source/intialize.c #
    webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.c
    webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.c
    webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.c
    webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.c
    webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.c
    webrtc/modules/audio_coding/codecs/isac/main/source/pitch_estimator.c
    webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.c
    webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.c
    webrtc/modules/audio_coding/codecs/isac/main/source/pitch_filter.c #
    webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.c
    # audio processing 模块
    webrtc/modules/audio_processing/vad/gmm.cc
    webrtc/modules/audio_processing/vad/pitch_based_vad.cc
    webrtc/modules/audio_processing/vad/pitch_internal.cc
    webrtc/modules/audio_processing/vad/pole_zero_filter.cc
    webrtc/modules/audio_processing/vad/standalone_vad.cc
    webrtc/modules/audio_processing/vad/vad_audio_proc.cc
    webrtc/modules/audio_processing/vad/vad_circular_buffer.cc
    webrtc/modules/audio_processing/vad/voice_activity_detector.cc
)

#function(prepend_path var prefix)
 #  set(listVar "")
  # foreach(f ${ARGN})
   #   list(APPEND listVar "${prefix}/${f}")
   #endforeach(f)
   #set(${var} "${listVar}" PARENT_SCOPE)
#endfunction(prepend_path)

#prepend_path(WEBRTC_SRC webrtc ${WEBRTC_SRC_})

add_executable(webrtc_vad test.cc ${WEBRTC_SRC_})
# target_link_libraries(webrtc-bf gflags pthread)
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") 
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O0 -Wall") 
target_link_libraries(webrtc_vad pthread)


